package com.sigmatrix.h5.service.db;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.sigmatrix.h5.config.TableUtils;
import com.sigmatrix.h5.entity.v2.DisTerminalShop;
import com.sigmatrix.h5.exception.MessageException;
import com.sigmatrix.h5.mapper.DisTerminalShopMapper;
import com.sigmatrix.h5.service.v2.CommonDBService;

/**
 * 
 * @author wei.wang
 *
 */
@Service
public class DisTerminalShopDBService extends CommonDBService<DisTerminalShopMapper, DisTerminalShop> {

	/**
	 * 获取该表所有的数据
	 * 
	 * @param tablePrefix
	 *            表前缀
	 * @return
	 */
	public List<DisTerminalShop> selectAll(String tablePrefix) {
		return baseMapper.selectAll(tablePrefix);
	}
	/**
	 * 获取该表所有的数据-分页
	 * 
	 * @param tablePrefix
	 *            表前缀
	 * @return
	 */
	public Page<DisTerminalShop> selectAllByPage(Page<DisTerminalShop> page,String tablePrefix) {
//		wrapper = (Wrapper<T>) SqlHelper.fillWrapper(page, );
		page.setRecords(baseMapper.selectAllByPage(page,tablePrefix));
		return page;
	}

	/**
	 * 根据ShopId更新Location数据。Location：province，city，citySubOrdinate，address
	 * 
	 * @param entity
	 *            为Location数据封装
	 * @return
	 */
	public int updateLocationById(DisTerminalShop entity) {
		return baseMapper.updateLocationById(entity);
	}
	
	/**
	 * 根据code获取DisTerminalShop
	 * 
	 * @param tablePrefix
	 * @param code
	 * @return
	 */
	public DisTerminalShop selectByCode(String eseCode,String code) {
		DisTerminalShop shop = new DisTerminalShop();
		shop.setTablePrefix(TableUtils.tablePrefixBy(eseCode));
		shop.setCode(code);
		List<DisTerminalShop> selectList = selectList(new EntityWrapper<DisTerminalShop>(shop));
		if(selectList!=null){
			if(selectList.size()>1){
				throw new MessageException("表disTerminalShop.selectByCode查询发生多条数据。code:"+code);
			}
			if(!selectList.isEmpty()){
				return selectList.get(0);
			}
		}
		return null;
	}

}